<?php
	include ("connection.php");
		   /* echo "<pre>";
	 		print_r($_GET);
			echo "</pre>"; */
	  		$type = (string) $_GET["type"];
		//=============================================
		//Lay tong so trang trong database
		//=============================================
		if($type == "count") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Nha_xuat_ban';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "list") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Nha_xuat_ban
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		}
		
		
		if($type == "countgg") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Giam_gia';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listgg") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Giam_gia
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		}
		
		
		
		
		
		
		if($type == "counttacgia") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Tac_gia';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listtacgia") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Tac_gia
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		}
		
		
		if($type == "countnbv") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Nhom_bai_viet';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listnbv") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Nhom_bai_viet
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
			
		}
		
		
		
		if($type == "countbv") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Bai_viet';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listbv") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT ID, Tieu_de, LEFT(Noi_dung,180) as Noi_dung, Thoi_gian, Trang_thai,ID_Nhom_bai_viet
					FROM Bai_viet
					ORDER BY ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
		
		
			
		if($type == "countttsach") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Tinh_trang_sach';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listttsach") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Tinh_trang_sach
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
		
		
			
		if($type == "counttinh") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Tinh_thanh_pho';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listtinh") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Tinh_thanh_pho
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		if($type == "counthuyen") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM quan_huyen';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listhuyen") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT quan_huyen.*, Ten_tinh_thanh_pho 
					FROM quan_huyen 
					INNER JOIN Tinh_thanh_pho
					ON quan_huyen.ID_tinh_thanh_pho = Tinh_thanh_pho.ID
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		if($type == "countsach") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Sach';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listsach") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Sach.*, Chu_de.Ten_chu_de, Tinh_trang_sach.Ten_tinh_trang
					FROM (Sach INNER JOIN Chu_de
					ON Sach.ID_Chu_de=Chu_de.ID) 
					INNER JOIN Tinh_trang_sach
					ON Sach.ID_Tinh_trang_sach=Tinh_trang_sach.ID
					ORDER BY ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		if($type == "countsachhh") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Sach WHERE (So_luong<=0 and ID_Tinh_trang_sach !=3 and ID_Tinh_trang_sach !=2)';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listsachhh") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Sach.*, Chu_de.Ten_chu_de, Tinh_trang_sach.Ten_tinh_trang
					FROM (Sach INNER JOIN Chu_de
					ON Sach.ID_Chu_de=Chu_de.ID) 
					INNER JOIN Tinh_trang_sach
					ON Sach.ID_Tinh_trang_sach=Tinh_trang_sach.ID
					WHERE (So_luong<=0 and ID_Tinh_trang_sach !=3 and ID_Tinh_trang_sach !=2)
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
			
		if($type == "countsachsaphh") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Sach WHERE (So_luong<=10 and So_luong> 0 and ID_Tinh_trang_sach !=3 and ID_Tinh_trang_sach !=2)';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listsachsaphh") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Sach.*, Chu_de.Ten_chu_de, Tinh_trang_sach.Ten_tinh_trang
					FROM (Sach INNER JOIN Chu_de
					ON Sach.ID_Chu_de=Chu_de.ID) 
					INNER JOIN Tinh_trang_sach
					ON Sach.ID_Tinh_trang_sach=Tinh_trang_sach.ID
					WHERE (So_luong<=10 and So_luong> 0 and ID_Tinh_trang_sach !=3 and ID_Tinh_trang_sach !=2)
					ORDER BY ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
		
		
		
		
		if($type == "countncc") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Nha_cung_cap';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listncc") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Nha_cung_cap
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
		
		if($type == "countntk") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Nhom_nguoi_dung';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listntk") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Nhom_nguoi_dung
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
			
		if($type == "countdsnh") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Hoa_don_nhap';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listdsnh") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Hoa_don_nhap.*, Ten_nha_cung_cap
					FROM Hoa_don_nhap INNER JOIN Nha_cung_cap
					ON Hoa_don_nhap.ID_Nha_cung_cap = Nha_cung_cap.ID
					order by ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
		
		
			
		if($type == "countdsbh") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Hoa_don';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listdsbh") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Hoa_don.*, Ho_va_ten, Ten_tinh_trang, Hoa_don.Tong_tien as tt
					FROM Hoa_don INNER JOIN Nguoi_dung ON
					Hoa_don.ID_Nguoi_dung = Nguoi_dung.ID
					INNER JOIN Tinh_trang_hoa_don ON
					Hoa_don.ID_Tinh_trang_hoa_don = Tinh_trang_hoa_don.ID
					order by Hoa_don.ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
			if($type == "countdsdathang") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Hoa_don WHERE ID_Tinh_trang_hoa_don="1"';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		
		
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listdsdathang") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Hoa_don.*, Ho_va_ten, Ten_tinh_trang, Hoa_don.Tong_tien as tt
					FROM Hoa_don INNER JOIN Nguoi_dung ON
					Hoa_don.ID_Nguoi_dung = Nguoi_dung.ID
					INNER JOIN Tinh_trang_hoa_don ON
					Hoa_don.ID_Tinh_trang_hoa_don = Tinh_trang_hoa_don.ID
					WHERE ID_Tinh_trang_hoa_don=1
					order by Hoa_don.ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		

		
			if($type == "countdsdangchuyen") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Hoa_don WHERE ID_Tinh_trang_hoa_don="2"';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		
		
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listdsdangchuyen") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Hoa_don.*, Ho_va_ten, Ten_tinh_trang, Hoa_don.Tong_tien as tt
					FROM Hoa_don INNER JOIN Nguoi_dung ON
					Hoa_don.ID_Nguoi_dung = Nguoi_dung.ID
					INNER JOIN Tinh_trang_hoa_don ON
					Hoa_don.ID_Tinh_trang_hoa_don = Tinh_trang_hoa_don.ID
					WHERE ID_Tinh_trang_hoa_don=2
					order by Hoa_don.ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
			if($type == "countdsthanhcong") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Hoa_don WHERE ID_Tinh_trang_hoa_don="3"';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		
		
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listdsthanhcong") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Hoa_don.*, Ho_va_ten, Ten_tinh_trang, Hoa_don.Tong_tien as tt
					FROM Hoa_don INNER JOIN Nguoi_dung ON
					Hoa_don.ID_Nguoi_dung = Nguoi_dung.ID
					INNER JOIN Tinh_trang_hoa_don ON
					Hoa_don.ID_Tinh_trang_hoa_don = Tinh_trang_hoa_don.ID
					WHERE ID_Tinh_trang_hoa_don=3
					order by Hoa_don.ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
		if($type == "countdshuy") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Hoa_don WHERE ID_Tinh_trang_hoa_don="4"';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		
		
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listdshuy") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Hoa_don.*, Ho_va_ten, Ten_tinh_trang, Hoa_don.Tong_tien as tt
					FROM Hoa_don INNER JOIN Nguoi_dung ON
					Hoa_don.ID_Nguoi_dung = Nguoi_dung.ID
					INNER JOIN Tinh_trang_hoa_don ON
					Hoa_don.ID_Tinh_trang_hoa_don = Tinh_trang_hoa_don.ID
					WHERE ID_Tinh_trang_hoa_don=4
					order by Hoa_don.ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		if($type == "countnguoidung") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Nguoi_dung ';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		
		
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listnguoidung") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT Nguoi_dung.*, Nhom_nguoi_dung.ID as ID_nhom, Nhom_nguoi_dung.Ten_nhom
					FROM Nguoi_dung INNER JOIN Nhom_nguoi_dung
					ON Nguoi_dung.ID_Nhom_nguoi_dung = Nhom_nguoi_dung.ID
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		
		
		
		if($type == "countlienhe") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Lien_he';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listlienhe") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Lien_he order by Thoi_gian desc
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		if($type == "countlienhekd") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Lien_he WHERE ID_Bo_phan =1';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listlienhekd") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Lien_he 
					WHERE ID_Bo_phan =1
					order by Thoi_gian desc
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		if($type == "countlienhetm") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Lien_he WHERE ID_Bo_phan =2';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listlienhetm") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *
					FROM Lien_he 
					WHERE ID_Bo_phan =2
					order by Thoi_gian desc
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
		if($type == "countbinhluanbv") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Binh_luan_bai_viet';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listbinhluanbv") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *, LEFT(Noi_dung, 120) as Noi_dung2
					FROM Binh_luan_bai_viet 
					order by Trang_thai desc, ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
		
			
		if($type == "countbinhluansach") {
			$items =(int) $_GET["items"];
			$sql = 'SELECT COUNT(id)	
					FROM Binh_luan_sach';
			$result = mysql_query ($sql, $link);
			$totalItem = mysql_result($result,0);
			$pages = $totalItem/$items;
			$total = array("total"=>0);
			$tmp = explode(".",$pages);
			if(count($tmp)>1){
			$pages = $tmp[0] + 1;
				}else{
						$pages = $tmp[0];	
					}
			$total["total"] = $pages;
			echo json_encode ($total);
			
		}
		
		//=============================================
		//Lay ra cac phan tu tuong ung voi trang hien thoi
		//=============================================
		if($type == "listbinhluansach") {
			/*echo "<pre>";
	 		print_r($_POST);
			echo "</pre>"; */
			$items = (int)$_POST["items"];
			$currentPage = (int) $_POST["currentPage"];
			$offset = ($currentPage -1) * $items;
			$sql ='SELECT *, LEFT(Noi_dung, 120) as Noi_dung2
					FROM Binh_luan_sach
					order by Trang_thai desc, ID DESC
					LIMIT ' .$offset. ','.$items;
			$result = mysql_query($sql, $link);
			$nxb = array();
			while ($row = mysql_fetch_assoc($result)){
				$nxb[]= $row;
			}
			/*echo "<pre>";
	 		print_r($nxb);
			echo "</pre>";  */
			echo json_encode($nxb);
		
		}
?>